{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 67,
   "source": [
    "import numpy as np\r\n",
    "from typing import Tuple"
   ],
   "outputs": [],
   "metadata": {}
  },
  {
   "cell_type": "markdown",
   "source": [
    "### 生成六个班的数据"
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "source": [
    "def generate_score(size: Tuple[int, int] = (50, 3)) -> np.ndarray:\r\n",
    "    random_data = np.random.random(size = size)\r\n",
    "    return np.round(random_data * 100, 1)\r\n",
    "\r\n",
    "\r\n",
    "classes = []\r\n",
    "for i in range(6):\r\n",
    "    classes.append(generate_score())\r\n"
   ],
   "outputs": [],
   "metadata": {}
  },
  {
   "cell_type": "markdown",
   "source": [
    "### 垂直叠加数组"
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 69,
   "source": [
    "scores = np.vstack(classes)"
   ],
   "outputs": [],
   "metadata": {}
  },
  {
   "cell_type": "markdown",
   "source": [
    "### 生成性别并合并成绩"
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "source": [
    "gender = np.random.randint(0, 2,size = (scores.shape[0],1))\r\n",
    "data = np.hstack([scores,gender])"
   ],
   "outputs": [],
   "metadata": {}
  },
  {
   "cell_type": "markdown",
   "source": [
    "### 统计指标"
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 71,
   "source": [
    "male_data = data[:,0:3][data[:,3]==1]\r\n",
    "female_data = data[:,0:3][data[:,3]==0]\r\n"
   ],
   "outputs": [],
   "metadata": {}
  },
  {
   "cell_type": "markdown",
   "source": [
    "#### 最大值"
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 72,
   "source": [
    "male_data.max(axis=0)\r\n",
    "female_data.max(axis=0)"
   ],
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "array([99.7, 98.8, 99.6])"
      ]
     },
     "metadata": {},
     "execution_count": 72
    }
   ],
   "metadata": {}
  },
  {
   "cell_type": "markdown",
   "source": [
    "#### 最小值"
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 73,
   "source": [
    "male_data.min(axis=0)\r\n",
    "female_data.min(axis=0)"
   ],
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "array([2.1, 0.2, 1. ])"
      ]
     },
     "metadata": {},
     "execution_count": 73
    }
   ],
   "metadata": {}
  },
  {
   "cell_type": "markdown",
   "source": [
    "#### 平均值"
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 74,
   "source": [
    "male_data.mean(axis=0)\r\n",
    "female_data.mean(axis=0)"
   ],
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "array([47.10540541, 51.05405405, 51.56959459])"
      ]
     },
     "metadata": {},
     "execution_count": 74
    }
   ],
   "metadata": {}
  },
  {
   "cell_type": "markdown",
   "source": [
    "#### 中位数"
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 75,
   "source": [
    "np.median(male_data,axis=-0)\r\n",
    "np.median(female_data,axis=-0)"
   ],
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "array([46.2 , 52.9 , 51.05])"
      ]
     },
     "metadata": {},
     "execution_count": 75
    }
   ],
   "metadata": {}
  },
  {
   "cell_type": "markdown",
   "source": [
    "#### 标准差"
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 76,
   "source": [
    "male_data.std(axis=0)\r\n",
    "female_data.std(axis=0)"
   ],
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "array([27.5657979 , 31.96242384, 31.08981466])"
      ]
     },
     "metadata": {},
     "execution_count": 76
    }
   ],
   "metadata": {}
  }
 ],
 "metadata": {
  "orig_nbformat": 4,
  "language_info": {
   "name": "python",
   "version": "3.8.11",
   "mimetype": "text/x-python",
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "pygments_lexer": "ipython3",
   "nbconvert_exporter": "python",
   "file_extension": ".py"
  },
  "kernelspec": {
   "name": "python3",
   "display_name": "Python 3.8.11 64-bit"
  },
  "interpreter": {
   "hash": "88c4a1b83521bb67c2a704a59fd8d4fbc808906c2f39c8cdcdb8c42e25302470"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}